<?php
		$sql="SELECT DISTINCT(stock_id),sup_name,pd_date,amount,paid,balance FROM  tbl_stocks WHERE type='entry' ";	
		$result=query($sql);
		 //**** start 
		$Num_Rows = mysql_num_rows($result);

		$Per_Page = 20;   // Per Page

		@$Page = $_GET["Page"];
		//if no page it will on first page
		if(!@$_GET["Page"])
		{
			$Page=1;
		}

		$Prev_Page = $Page-1;
		$Next_Page = $Page+1;
		
		$Page_Start = (($Per_Page*$Page)-$Per_Page);
		
		if($Num_Rows<=$Per_Page)
		{
			$Num_Pages =1;
		}
		else if(($Num_Rows % $Per_Page)==0)
		{
			$Num_Pages =($Num_Rows/$Per_Page) ;
		}
		else
		{
			$Num_Pages =($Num_Rows/$Per_Page)+1;
			$Num_Pages = (int)$Num_Pages;
		}

		$First_Page =1;
		$Last_Page =$Num_Pages;
		// After concetenate have to space
		$sql .=" ORDER BY id DESC LIMIT $Page_Start , $Per_Page";
        $result  = query($sql);

		$intRows = 0;	
			while($row = fetch_object($result))
			{
				$intRows++;
				$mysqldate=$row->pd_date;
				$phpdate = strtotime( $mysqldate );
				$phpdate = date("d/m/Y",$phpdate);		
	  ?>
  	  <tr>
            <td width="100"><?php echo $row->stock_id; ?></td>
            <td width="100"><?php echo $row->sup_name; ?></td>
            <td width="100"><?php echo $phpdate; ?></td>
            <td width="100"><?php echo $row->amount; ?></td>
            <td width="100"><?php echo $row->paid; ?></td>
            <td width="100"><?php echo $row->balance; ?></td>
            <td width="100"> 
            	<a href="index.php?page=add_stock&action=add_stock_edit&stock_id=<?php echo $row->stock_id;?>"><img src="images/edit.png" border="0" alt="Edit"></a>
                <a onclick="return confirm('Do you want to delete this record..?');" href="index.php?page=add_stock&action=add_stock&stock_id=<?php echo $row->stock_id;?>"><img src="images/delete.png" border="0" alt="delete"></a>
            </td>
 	</tr> 
     <?php
		}
	 ?>
</table>
	 <div class="pagination">
    		<div class="totalRecord">
            	<?php 
					echo "Total: ".$Num_Rows. " Records, ";
					echo $Num_Pages. " Pages";
				?>
            </div>
			<?php
				if($Prev_Page)
				{
					echo " <div  class='back'> <a href='index.php?page=add_stock&action=add_stock&Page=$First_Page'><< First</a></div> ";
					echo " <div  class='back'> <a href='index.php?page=add_stock&action=add_stock&Page=$Prev_Page'><< Back</a></div> ";
				}
		
					for($i=1; $i<=$Num_Pages; $i++){
						if($i != $Page)
						{
							echo "<div  class='page'><a href='index.php?page=add_stock&action=add_stock&Page=$i'>$i</a></div>";
						}
						else
						{
							echo "<div  class='curent'> $i </div>";
						}
					}
				if($Page!=$Num_Pages)
				{
					echo " <div  class='next'><a href ='index.php?page=add_stock&action=add_stock&Page=$Next_Page'>Next>></a></div> ";
					echo " <div  class='next'><a href ='index.php?page=add_stock&action=add_stock&Page=$Last_Page'>Last>></a></div> ";
					
				}	
			?>
    </div>